//
//  MacroSetting.h
//  SYFCode
//
//  Created by Angel_Yan on 16/3/23.
//  Copyright © 2016年 银联科技. All rights reserved.
//

#ifndef MacroSetting_h
#define MacroSetting_h


#define JSON @"json"


/**
 *  定义单例
 */
#pragma mark - Singleton

#define DEFINE_SHARED_INSTANCE_USING_BLOCK(block) \
static dispatch_once_t pred = 0; \
__strong static id _sharedObject = nil; \
dispatch_once(&pred, ^{ \
_sharedObject = block(); \
}); \
return _sharedObject; \


#define kUUIDString [[UIDevice currentDevice].identifierForVendor UUIDString]
#define kAppDelegate ((ZBAppDelegate *)[UIApplication sharedApplication].delegate)

//NavBar高度
#define kNavigationBar_Height 44.0
#define kStatusBar_Height (SCREEN_HEIGHT == 812.0 ? 40 : 20)
#define kTabBar_Height 50.0

//定义屏幕尺寸
#define SCREEN_WIDTH  [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

#define SCREEN_WIDTH_BASE 375.0
#define SCREEN_HEIGHT_BASE 667.0

#define SafeAreaTopHeight (SCREEN_HEIGHT == 812.0 ? 88 : 64)
#define SafeAreaBottomHeight (SCREEN_HEIGHT == 812.0 ? 34 : 0)
#define SafeAreaTabbarHeight (SCREEN_HEIGHT == 812.0?83.0f:49.0f)

#define AdjustsScrollViewInsetNever(controller,view) if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;} else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}


// 屏幕适应 - 设计图按照4.7的比例
#define AUTO_X (SCREEN_WIDTH/SCREEN_WIDTH_BASE)
#define AUTO_Y (SCREEN_HEIGHT/SCREEN_HEIGHT_BASE)
#define AUTO_HIGHT(number) ceilf(number * (AUTO_Y))
#define AUTO_WIDTH(number) ceilf(number * (AUTO_X))

/**
 *  按照比例计算视频屏幕
 *
 *  @param x 4.7屏幕 如6s
 *  @param y 4.7屏幕 如6s
 *  @param w 4.7屏幕 如6s
 *  @param h 4.7屏幕 如6s
 *
 *  @return 按比例计算后的frame
 */
#define RECTFRAME(x,y,w,h) CGRectMake(x, y, w, h)
#define RECTMAKE(x,y,w,h) CGRectMake(AUTO_WIDTH(x), AUTO_HIGHT(y), AUTO_WIDTH(w), AUTO_HIGHT(h))

#define FRAME_ORIGIN(aFrame)              ((aFrame).origin)
#define FRAME_X(aFrame)                   ((aFrame).origin.x)
#define FRAME_Y(aFrame)                   ((aFrame).origin.y)

#define FRAME_SIZE(aFrame)                ((aFrame).size)
#define FRAME_HEIGHT(aFrame)              ((aFrame).size.height)
#define FRAME_WIDTH(aFrame)               ((aFrame).size.width)

/*修改frame对象的x、y、width、height属性值*/
#define FRAME_CHANGE_X(aFrame,x)          CGRectMake(x, (aFrame).origin.y, (aFrame).size.width, (aFrame).size.height)
#define FRAME_CHANGE_Y(aFrame,y)          CGRectMake((aFrame).origin.x, y, (aFrame).size.width, (aFrame).size.height)
#define FRAME_CHANGE_WIDTH(aFrame,w)      CGRectMake((aFrame).origin.x, (aFrame).origin.y, w, (aFrame).size.height)
#define FRAME_CHANGE_HEIGHT(aFrame,h)     CGRectMake((aFrame).origin.x, (aFrame).origin.y, (aFrame).size.width, h)

// 向左移动offset位移后得到frame对象
#define FRAME_MOVE_Left(aFrame,offset)    CGRectMake((aFrame).origin.x-(offset), (aFrame).origin.y, (aFrame).size.width, (aFrame).size.height)
// 向右移动offset位移后得到frame对象
#define FRAME_MOVE_Right(aFrame,offset)   CGRectMake((aFrame).origin.x+(offset), (aFrame).origin.y, (aFrame).size.width, (aFrame).size.height)
// 向上移动offset位移后得到frame对象
#define FRAME_MOVE_Up(aFrame,offset)      CGRectMake((aFrame).origin.x, (aFrame).origin.y-(offset), (aFrame).size.width, (aFrame).size.height)
// 向下移动offset位移后得到frame对象
#define FRAME_MOVE_Down(aFrame,offset)    CGRectMake((aFrame).origin.x, (aFrame).origin.y+(offset), (aFrame).size.width, (aFrame).size.height)

#define VIEW_BOUNDS(aView)       ((aView).bounds)

#define VIEW_FRAME(aView)        ((aView).frame)

#define VIEW_ORIGIN(aView)       ((aView).frame.origin)
#define VIEW_X(aView)            ((aView).frame.origin.x)
#define VIEW_Y(aView)            ((aView).frame.origin.y)

#define VIEW_SIZE(aView)         ((aView).frame.size)
#define VIEW_HEIGHT(aView)       ((aView).frame.size.height)  // 视图高度
#define VIEW_WIDTH(aView)        ((aView).frame.size.width)   // 视图宽度

#define VIEW_X_Right(aView)      ((aView).frame.origin.x + (aView).frame.size.width)  // 视图右边界x坐标
#define VIEW_Y_Bottom(aView)     ((aView).frame.origin.y + (aView).frame.size.height) // 视图底部y坐标

#define AdjustsScrollViewInsetNever(controller,view) if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;} else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}


//iphone 手机的尺寸
//3.5
//4.0
//4.7
//5.5
#define iPhone_3_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone_4_0 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone_4_7 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone_5_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

//判断设备，
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6p ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone4s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(320, 480), [[UIScreen mainScreen] currentMode].size) : NO)

#define ScreenScale [UIScreen mainScreen].scale // 屏幕分辨率倍数
//是否为ipad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//是否为 retain 屏
#define isRetina !iPhone4

#define kAFLocalize(key)            NSLocalizedString(key, nil)

/**
 *  注册通知与发送通知
 */
#pragma mark - Notification

#define addNOTIbserver(_selector,_name) ([[NSNotificationCenter defaultCenter] addObserver:self selector:_selector name:_name object:nil])
#define removeNOTIbserver(_name) ([[NSNotificationCenter defaultCenter] removeObserver:self name:_name object:nil])
#define removeNOTIbserverAll ([[NSNotificationCenter defaultCenter] removeObserver:self])
#define postNOTI(_name) ([[NSNotificationCenter defaultCenter] postNotificationName:_name object:nil userInfo:nil])
#define postNOTIWithObj(_name,_obj) ([[NSNotificationCenter defaultCenter] postNotificationName:_name object:_obj userInfo:nil])
#define postNOTIWithInfo(_name,_info) ([[NSNotificationCenter defaultCenter] postNotificationName:_name object:nil userInfo:_info])

#define kStrYuzaiDesc      @"strYuzaiDesc"
#define kStrYuzhuangDesc   @"strYuzhuangDesc"
#define kStrYubaoDesc      @"strYubaoDesc"
#define kStrYugeDesc       @"strYugeDesc"
#define kStrYuwangDesc     @"strYuwangDesc"

#define kStrRefreshing  @"strRefreshing"
#define kStrLoading     @"strLoading"

#define kStrSuccess     @"strSuccess"
#define kStrError       @"strError"
#define kStrWarning     @"strWarning"
#define kStrFail        @"strFail"

#define kStrMorning     @"strMorning"
#define kStrAfternood   @"strAfternood"
#define kStrYesterday   @"strYesterday"
#define kStrBefYesterday @"strBefYesterday"

#define kStrYear        @"strYear"
#define kStrMonth       @"strMonth"
#define kStrDay         @"strDay"
#define kStrHour        @"strHour"
#define kStrMinute      @"strMinute"
#define kStrSecond      @"strSecond"
#define kStrCurrentYear     @"strCurrentYear"
#define kStrCurrentMonth    @"strCurrentMonth"
#define kStrCurrentWeek     @"strCurrentWeek"
#define kStrToday           @"strToday"


#define kStrSunday           @"strSunday"
#define kStrSaturday         @"strSaturday"
#define kStrFriday           @"strFriday"
#define kStrMonday           @"strMonday"
#define kStrTuesday          @"strTuesday"
#define kStrWednesday        @"strWednesday"
#define kStrThursday         @"strThursday"

/**
 *  stringUrl 转成Url
 *
 *  @param string <#string description#>
 *
 *  @return <#return value description#>
 */
#define StringToURL(string) [NSURL URLWithString:[(string) stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]

// 文件写入路径
#define NSsearchPathLast  NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject

#define DATESTRING(utime,format)  [NSDate timeStringFromDate:[NSDate dateWithTimeIntervalSince1970:utime/1000] withFormat:format]


#   define kTextAlignmentCenter    NSTextAlignmentCenter
#   define kTextAlignmentLeft      NSTextAlignmentLeft
#   define kTextAlignmentRight     NSTextAlignmentRight

// 下面是自己定义的，不需要垂直居中的
#   define kTextAlignmentCenterC   NSTextAlignmentCenter|100
#   define kTextAlignmentLeftC     NSTextAlignmentLeft|100
#   define kTextAlignmentRightC    NSTextAlignmentRight|100

#   define kTextLineBreakByWordWrapping      NSLineBreakByWordWrapping
#   define kTextLineBreakByCharWrapping      NSLineBreakByCharWrapping
#   define kTextLineBreakByClipping          NSLineBreakByClipping
#   define kTextLineBreakByTruncatingHead    NSLineBreakByTruncatingHead
#   define kTextLineBreakByTruncatingTail    NSLineBreakByTruncatingTail
#   define kTextLineBreakByTruncatingMiddle  NSLineBreakByTruncatingMiddle

/** 增加工作线程与主线程宏定义 */
#define kQueueGlobal     dispatch_get_global_queue(0, 0)
#define kQueueMain       dispatch_get_main_queue()

#define kQueueTimer                    dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, kQueueMain)
#define kQueueSetTimer(timer)          dispatch_source_set_timer(timer, DISPATCH_TIME_NOW,(uint64_t)(1.0 * NSEC_PER_SEC), 0)
#define kQueueTimerBlock(timer,block)  dispatch_source_set_event_handler(timer,block)
#define kQueueTimerCancel(timer)       dispatch_source_cancel(timer)
#define kQueueTimerStar(timer)         dispatch_resume(timer)
#define kQueueTimerPause(timer)        dispatch_suspend(timer)

//单例
#define singleH(name) +(instancetype)share##name;

#if __has_feature(objc_arc)
#define singleM(name) static id _instance;\
+(instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
\
+(instancetype)share##name\
{\
return [[self alloc]init];\
}\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
\
-(id)mutableCopyWithZone:(NSZone *)zone\
{\
return _instance;\
}

#else
#define singleM static id _instance;\
+(instancetype)allocWithZone:(struct _NSZone *)zone\
{\
static dispatch_once_t onceToken;\
dispatch_once(&onceToken, ^{\
_instance = [super allocWithZone:zone];\
});\
return _instance;\
}\
\
+(instancetype)shareTools\
{\
return [[self alloc]init];\
}\
-(id)copyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
\
-(id)mutableCopyWithZone:(NSZone *)zone\
{\
return _instance;\
}\
-(oneway void)release\
{\
}\
\
-(instancetype)retain\
{\
return _instance;\
}\
\
-(NSUInteger)retainCount\
{\
return MAXFLOAT;\
}
#endif


//G－C－D，这个使用时一定注意内部不要包异步处理方法
#define WORK_BACK(block) dispatch_async(kQueueGlobal, block)
#define WORK_MAIN(block) dispatch_async(kQueueMain, block)
#define WORK_MSG(block) dispatch_async(kQueueMSG, block)
/******* 控制状态栏显示加载activity ********/
#define ShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES
#define HideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO

#define ShowStatusBar() [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]
#define HideStatusBar() [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]

#define IsLandscape   (SCREEN_WIDTH>SCREEN_HEIGHT?YES:NO)
#define kChatFaceBoardHeight                     216.0f

//获取系统版本;iOS10也有效
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectWithIndex:0])

#define iPad ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(768, 1024), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPadRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1536, 2048), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPadPro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(2048, 2732), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define isRetina !iPhone4
#define isSimulator [[AFFLAPIPublic deviceVersion] containsString:@"Simulator"]

//View圆角和加边框
#define KViewBorderRadius(View,Radius,Width,Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

// View圆角
#define ViewRadius(View,Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]

//强弱引用
#define kWeakSelf(type)__weak typeof(type)weak##type = type;
#define kStrongSelf(type)__strong typeof(type)type = weak##type;

//property属性快速声明
#define PropertyString(s)@property(nonatomic,copy)NSString * s
#define PropertyNSInteger(s)@property(nonatomic,assign)NSIntegers
#define PropertyFloat(s)@property(nonatomic,assign)floats
#define PropertyLongLong(s)@property(nonatomic,assign)long long s
#define PropertyNSDictionary(s)@property(nonatomic,strong)NSDictionary * s
#define PropertyNSArray(s)@property(nonatomic,strong)NSArray * s
#define PropertyNSMutableArray(s)@property(nonatomic,strong)NSMutableArray * s



//image
#define kIMG_Name(imgName)        [UIImage imageNamed:(imgName)]
#define kIMG_ImgWidth(img)        ((img).size.width)
#define kIMG_ImgHeight(img)       ((img).size.height)
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
#endif /* MacroSetting_h */
